﻿@using DirectSell.Model.Money
@using Webdiyer.WebControls.Mvc;
@model  PagedList<MoneyTransfor>
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/User/Views/Shared/UserLayout.cshtml";
}

<!-- APP MAIN ==========-->
<main id="app-main" class="app-main">
    <div class="wrap">
        <section class="app-content">
            <div class="widget">
                <header class="widget-header title2">
                    <h4 class="widget-title">内部转换</h4>
                </header><!-- .widget-header -->
                <hr class="widget-separator">

                <div class="widget-body">
                    <form id="form1" class="form-horizontal">
                        <div class="form-group">
                            <label for="#" class="col-sm-2 control-label">奖金金额</label>
                            <div class="col-sm-5">
                                <input class="form-control" id="bonus" type="text" readonly="readonly" >
                            </div>
                        </div><!-- .form-group -->

                        <div class="form-group">
                            <label for="#" class="col-sm-2 control-label">电子币金额</label>
                            <div class="col-sm-5">
                                <input class="form-control" type="text" id="virtualmoney" readonly="readonly" >
                            </div>
                        </div><!-- .form-group -->

                        <div class="form-group">
                            <label for="#" class="col-sm-2 control-label">互换类型</label>
                            <div class="col-sm-5">
                                <select id="Type" name="Type" class="form-control" data-plugin="select2">
                                    <option selected="selected" value="0">奖金转电子币</option>
                                </select>
                            </div><!-- END column -->
                        </div><!-- .form-group -->

                        <div class="form-group">
                            <label for="#" class="col-sm-2 control-label">互换数量</label>
                            <div class="col-sm-3">
                                <input class="form-control" name="Amount" required type="text" placeholder="请输入互换数量">
                            </div>
                        </div><!-- .form-group -->

                        <div class="form-group">
                            <label for="#" class="col-sm-2 control-label">二级密码</label>
                            <div class="col-sm-5">
                                <input class="form-control" name="SecondPassWord" required type="password" placeholder="请输入二级密码">
                            </div>
                        </div><!-- .form-group -->

                        <div class="form-group">
                            <label for="#" class="col-sm-2 control-label">验证码</label>
                            <div class="col-sm-4">
                                <input class="form-control" name="CheckCode" type="text" required placeholder="请输入验证码">
                            </div>
                            <div class="col-sm-1"><img id="code" src="/User/MoneyTransfor/GetImageValiDateCode" style="width:60px;height:40px;"></div>
                        </div><!-- .form-group -->

                        <div class="form-group">
                            <div class="col-sm-8 text-center">
                                <button type="submit" class="btn btn-info">确认互换</button>
                            </div>
                        </div>
                    </form>
                </div><!-- .widget-body -->
            </div><!-- .widget -->

            <div class="widget">
                <header class="widget-header title2">
                    <h4 class="widget-title">内部转换</h4>
                </header><!-- .widget-header -->
                <hr class="widget-separator">
                <div class="widget-body mt15">
                    <div class="table-responsive">
                        <div class="text-center p-t-sm p-b-sm">
                            <nav class="page-redcolor">
                                <div id="orders">
                                    <div id="dvCategoryResults">
                                        @Html.Partial("List", Model)
                                    </div>
                                    <div style="width:100%;overflow:auto;">
                                        <div style="float:right">Go to page<select id="pib"></select></div>
                                @Ajax.Pager(Model, new PagerOptions
                               {
                                   PageIndexParameterName = "page",
                                   ContainerTagName = "ul",
                                   CssClass = "pagination",
                                   PageIndexBoxId = "pib",
                                   Id = "mypager",
                                   CurrentPagerItemTemplate = "<li class=\"active\"><a href=\"#\">{0}</a></li>",
                                   DisabledPagerItemTemplate = "<li class=\"disabled\"><a>{0}</a></li>",
                                   PagerItemTemplate = "<li>{0}</li>"
                               }).AjaxOptions(a => a.SetUpdateTargetId("orders").EnablePartialLoading())
                                    </div>
                                </div>
                                @section scripts{ @{Html.RegisterMvcPagerScriptResource();}}
                                </nav>
                            </div>
                    </div>

                </div><!-- .widget-body -->
            </div><!-- .widget -->
        </section><!-- #dash-content -->
    </div><!-- .wrap -->
    <!-- APP FOOTER -->
    <div class="wrap p-t-0">
        <footer class="app-footer">
            <div class="clearfix">
                <div class="copyright text-center w100">@DirectSell.Common.Url.CommonConfig.companyName &copy;</div>
            </div>
        </footer>
    </div>
    <!-- /#app-footer -->
</main>
<!--========== END app main -->
<script>
    //点击验证码图片，更换验证码
    $("#code").click(function () {
        $(this).attr("src", "/User/MoneyTransfor/GetImageValiDateCode?time=" + (new Date()).getTime())
    });
    $(function () {
        queryBalance();
    })
    //余额
    function queryBalance() {
        $.ajax({
            type: "post",
            url: "/User/MoneyTransfor/QueryBalance",
        }).success(function (message) {
            $('#bonus').val(message.realmoney);
            $('#virtualmoney').val(message.virtualmoney);
        })
    }
    //提交表单
    $('#form1').on('submit', function () {
        layer.confirm('确定提交本次操作?', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            formPost();
        }, function () {
            layer.close();
        });
        event.preventDefault() //阻止form表单默认提交
    })
    function formPost() {
        //加载层
        var index = layer.load(1, {
            shade: [0.1, '#fff']
        });
        $.ajax({
            type: "post",
            url: "/User/MoneyTransfor/Tranfor",
            data: $('#form1').serialize(),
        }).success(function (message) {
            if (message != '成功') {
                layer.msg(message, { icon: 2 });
            }
            else {
                queryBalance();
                layer.msg('转换成功', { icon: 1 });
            }
        }).fail(function (err) {
            layer.msg('系统错误,请稍后重试', { icon: 2 });
        })
        layer.close(index)//关闭加载层
    }
</script>
